﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
#if NETFX_CORE
using Windows.UI.Xaml;
using Windows.Foundation;
using System.Windows.Interactivity;
#else
using System.Windows.Interactivity;
#endif

namespace ArchiSimple.Windows
{
    public class PositionBehavior : Behavior<FrameworkElement>
    {
        public Point MousePoint 
        {
            get { return (Point)GetValue(MousePointProperty); }
            set { SetValue(MousePointProperty, value); }
        }

        // Using a DependencyProperty as the backing store for X.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MousePointProperty =
            DependencyProperty.Register("MousePoint", typeof(Point), typeof(PositionBehavior), new PropertyMetadata(new Point()));

        protected override void OnAttached()
        {
            base.OnAttached();

#if NETFX_CORE
            this.AssociatedObject.PointerMoved += (sender, e) =>
            {
                var position = e.GetCurrentPoint(this.AssociatedObject);
                this.MousePoint = position.Position;
            };
#else
            this.AssociatedObject.MouseMove += (sender, e) =>
            {
                var position = e.GetPosition(this.AssociatedObject);
                this.MousePoint = position;
            };
#endif
        }
    }
}
